package com.fb.fbvedioplayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.fb.fbvedioplayer.CustomView.FBVideoPlayerStandard;


public class AdapterRecyclerViewVideo extends RecyclerView.Adapter<AdapterRecyclerViewVideo.MyViewHolder> {

	public static final String TAG = "AdapterRecyclerViewVideo";
	int[] videoIndexs = {0,
						 1,
						 2,
						 3,
						 4,
						 5,
						 6,
						 7};
	private Context context;

	public AdapterRecyclerViewVideo(Context context) {
		this.context = context;
	}

	@Override
	public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_videoview, parent, false));
		return holder;
	}

	@SuppressLint("LongLogTag")
	@Override
	public void onBindViewHolder(MyViewHolder holder, int position) {
		Log.i(TAG, "onBindViewHolder [" + holder.jzVideoPlayer.hashCode() + "] position=" + position);
		String videourl =ApplicationDemo.getProxy(holder.jzVideoPlayer.getContext()).getProxyUrl(VideoConstant.videoUrlList[position]);
		holder.jzVideoPlayer.setVideo(videourl, VideoConstant.videoTitles[position],
									  FBVideoPlayerStandard.SCREEN_WINDOW_LIST);
		Glide.with(holder.jzVideoPlayer.getContext())
			 .load(VideoConstant.videoThumbList[position])
			 .apply(RequestOptions.centerCropTransform())
			 .into(holder.jzVideoPlayer.thumbImageView);
	}

	@Override
	public int getItemCount() {
		return videoIndexs.length;
	}

	class MyViewHolder extends RecyclerView.ViewHolder {

		FBVideoPlayerStandard jzVideoPlayer;

		public MyViewHolder(View itemView) {
			super(itemView);
			jzVideoPlayer = itemView.findViewById(R.id.videoplayer);
		}
	}

}
